package com.example.eddie.test.MyAdapter;

/**
 * Created by eddie on 28/08/2017.
 */

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.eddie.test.PoJo.TeacherClassInfo;
import com.example.eddie.test.R;

import java.util.ArrayList;
import java.util.List;

public class InfoAdapter extends ArrayAdapter {

    private Context context;
    private int resource;
    private List<TeacherClassInfo> list = new ArrayList<>();

    public InfoAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List objects) {
        super(context, resource, objects);

        this.context = context;
        this.resource = resource;
        this.list = objects;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        View view = null;

        if (convertView!=null) {
            view = convertView;
        }else {
            view = LayoutInflater.from(context).inflate(resource, parent, false);
        }

        TextView day = (TextView) view.findViewById(R.id.day);
        TextView time1 = (TextView) view.findViewById(R.id.time1);
        TextView time2 = (TextView) view.findViewById(R.id.time2);
        TextView classInfo = (TextView) view.findViewById(R.id.class_info);

        day.setText(list.get(position).getDay());
        time1.setText(list.get(position).getTime1());
        time2.setText(list.get(position).getTime2());
        classInfo.setText(list.get(position).getInfo());


        return view;
    }
}